<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>

        // TODO 字符串解构
        // 字符串被转换成了一个类似数组的对象
        let [a,b,c,d,e] = 'Tendo'
        console.log(a,b,c,d,e);// T e n d o
        let{length:len} = 'Tedno'
        console.log(len);// 5


        // TODO 数字解构
        let {toString} = 123;
        console.log(toString);// ƒ toString() { [native code] }
        console.log(toString === Number.prototype.toString); //true
        /**
         * 举个例子
         * */
        var num = 123;
        console.log(num, num.toString()); // 123 "123"


        // TODO 布尔值解构
        let {toString: s} = true;
        console.log(s);
        console.log(s === Boolean.prototype.toString); //true
        //数值和布尔值的包装对象都有toString属性，因此变量s都能取到值
        /**
         * 解构赋值的规则是，只要等号右边的值不是对象或数组，就先将其转为对象。
         * 由于undefined和null无法转为对象，所以对他们进行解构赋值，都会报错
         * */
        let { prop: x } = {};
        console.log(x); // undefined
        // let { prop: x } = undefined; // Cannot destructure property 'prop' of 'undefined' as it is undefined.
        // let { prop: y } = null; // Cannot destructure property 'prop2' of 'null' as it is null.


    </script>
</head>
<body>
    
</body>
</html>